package risk.export.record.config;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;


@Configuration
public class RedisConfig {
    private static final Logger logger = LoggerFactory.getLogger(RedisConfig.class);

    @Bean(name = {"JedisPool"})
    public JedisPool redisDataSource() {
        logger.warn("=======》RedisDataSource初始化了《=======");
        JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
        // 最大空闲数
        jedisPoolConfig.setMaxIdle(1);
        // 连接池的最大数据库连接数
        jedisPoolConfig.setMaxTotal(5);
        //资源池确保的最少空闲连接数
        jedisPoolConfig.setMinIdle(1);
        //是否开启空闲资源检测
        jedisPoolConfig.setTestWhileIdle(true);
        String host = ConfigMap.rs1.get("host");
        String password = ConfigMap.rs1.get("password");
        return new JedisPool(jedisPoolConfig, host, 6379, 2000, password);
    }

}
